(function(){
	var MultiUpd=window.MultiUpd=function(p_jsnSwfCfg,p_jsnPara){
		this.getFunc(this,MultiUpd._objParent)();
		var jsnSwfCfg={
			swfupload_preload_handler:this.preLoad,
			swfupload_load_failed_handler:this.loadFailed,
			file_dialog_start_handler:this.fileDialogStart,
			file_queued_handler:this.fileQueued,
			file_queue_error_handler:this.fileQueueError,
			file_dialog_complete_handler:this.fileDialogComplete,
			upload_progress_handler:this.uploadProgress,
			upload_error_handler:this.uploadError,
			upload_success_handler:this.uploadSuccess,
			upload_complete_handler:this.uploadComplete,
		};
		for( var strKey in p_jsnSwfCfg){
			jsnSwfCfg[strKey]=p_jsnSwfCfg[strKey];
		}
		jsnSwfCfg.custom_settings.multiupd=this;
		this.objSwfUpd=new SWFUpload(jsnSwfCfg);
		this.bindEvent(window,'unload',this.objSwfUpd.destroy);
		this._arrPrivate['arrList']={};
		this._arrPrivate['arrProgress']={
			intTotalBytes:0,
			intLoadedBytes:0
		};
		this._arrPrivate['arrMultiUpdConfig']={
			totalprogress_placeholder_id:p_jsnPara.totalprogress_placeholder_id,
			filelist_placeholder_id:p_jsnPara.filelist_placeholder_id,
			file_post_name:p_jsnSwfCfg.file_post_name,
			load_error_msg:p_jsnPara.load_error_msg,
			
			queue_full_msg:p_jsnPara.queue_full_msg,
		};
	}.extend(Base);
	pt=MultiUpd.prototype;
	/* 控件加载前执行 */
	pt.preLoad=function(){
		if(!this.support.loading){
			return false;
		}
	},
	/* 控件加载失败执行 */
	pt.loadFailed=function(){//可以自定义
		var objMultiUpd=this.settings.custom_settings.multiupd;
		alert(objMultiUpd._arrPrivate['arrMultiUpdConfig'].load_error_msg);
	},
	/* 在选择文件框关闭后执行 */
	pt.fileDialogStart=function(){
		/*this._arrPrivate['arrList']={};
		this._arrPrivate['arrProgress']={
			intTotalBytes:0,
			intLoadedBytes:0
		};*/
	},
	/* 选择文件框关闭后有文件加入上传队列时执行 */
	pt.fileQueued=function(p_objFile){
		//alert(p_objFile.name+' queued');
		var objMultiUpd=this.settings.custom_settings.multiupd;
		objMultiUpd._arrPrivate['arrList'][p_objFile.id]={
			status:'queue',
			id:p_objFile.id,
			name:p_objFile.name,
			size:p_objFile.size
		};
	},
	/* 文件加入队列出现错误时执行 */
	pt.fileQueueError=function(p_objFile,p_intErrCode,p_strMsg){//可以自定义
		//alert(p_objFile.name+' queued error');
		var objMultiUpd=this.settings.custom_settings.multiupd;
		if(-100===p_intErrCode){//队列满了
			alert(objMultiUpd._arrPrivate['arrMultiUpdConfig'].queue_full_msg);
		}else{
			objMultiUpd._arrPrivate['arrList'][p_objFile.id]={
				status:'fail',
				id:p_objFile.id,
				name:p_objFile.name,
				size:p_objFile.size,
				code:p_intErrCode,
				msg:p_strMsg
			};
		}
	},
	/* 选择文件框关闭后有文件加入上传队列成功或者失败后执行 */
	pt.fileDialogComplete=function(p_intNumFilesSelected,p_intNumFilesQueued){//可以自定义
		//alert('file dialog complete');
		var objMultiUpd=this.settings.custom_settings.multiupd;
		for( var strKey in objMultiUpd._arrPrivate['arrList']){
			if('queue'==objMultiUpd._arrPrivate['arrList'][strKey].status){
				objMultiUpd._arrPrivate['arrProgress'].intTotalBytes=objMultiUpd._arrPrivate['arrProgress'].intTotalBytes+objMultiUpd._arrPrivate['arrList'][strKey].size;
			}
		}
		objMultiUpd.drawAllProcessor(0,objMultiUpd._arrPrivate['arrProgress'].intTotalBytes);
		if(p_intNumFilesQueued>0){
			this.startUpload();
		}else{
			if(p_intNumFilesSelected>0){
				objMultiUpd.drawPic();
			}
		}
	},
	/* flash触发上传进度函数 */
	pt.uploadProgress=function(p_objFile,p_intBytesLoaded){//可以自定义
		var objMultiUpd=this.settings.custom_settings.multiupd;
		objMultiUpd.drawAllProcessor(objMultiUpd._arrPrivate['arrProgress'].intLoadedBytes+p_intBytesLoaded,objMultiUpd._arrPrivate['arrProgress'].intTotalBytes);
	},
	/* 上传被终止或者没有成功完成 */
	pt.uploadError=function(p_objFile,p_intErrCode,p_strMsg){
		//alert(p_objFile.name+' upload error');
		var objMultiUpd=this.settings.custom_settings.multiupd;
		objMultiUpd._arrPrivate['arrList'][p_objFile.id]={
			status:'fail',
			id:p_objFile.id,
			name:p_objFile.name,
			size:p_objFile.size,
			code:p_intErrCode,
			msg:p_strMsg
		};
	},
	/* 每次成功上传一个文件就会触发 */
	pt.uploadSuccess=function(p_objFile,p_strData){
		//alert(p_objFile.name+' upload success');
		var objMultiUpd=this.settings.custom_settings.multiupd;
		objMultiUpd._arrPrivate['arrList'][p_objFile.id]={
			status:'ok',
			id:p_objFile.id,
			name:p_objFile.name,
			size:p_objFile.size,
			data:p_strData
		};
	},
	/* 每次上传完成一个文件的上传,不管成功还是失败都会触发 */
	pt.uploadComplete=function(p_objFile){//可以自定义
		var objMultiUpd=this.settings.custom_settings.multiupd;
		objMultiUpd._arrPrivate['arrProgress'].intLoadedBytes=objMultiUpd._arrPrivate['arrProgress'].intLoadedBytes+p_objFile.size;
		for(var strFileID in objMultiUpd._arrPrivate['arrList']){
			if(strFileID==p_objFile.id){
				var jsnData=eval('('+objMultiUpd._arrPrivate['arrList'][strFileID].data+')');
				objMultiUpd._arrPrivate['arrList'][strFileID].key=jsnData[objMultiUpd._arrPrivate['arrMultiUpdConfig'].file_post_name].FILEKEY;
				objMultiUpd._arrPrivate['arrList'][strFileID].ext=jsnData[objMultiUpd._arrPrivate['arrMultiUpdConfig'].file_post_name].EXTENSION;
			}
		}
		objMultiUpd.drawPic();
		if(this.getStats().files_queued>0){
			this.startUpload();
		}
	},
	/* 绘画上传进度条 */
	pt.drawAllProcessor=function(p_intByteLoaded,p_intTotal){//可以自定义
		if(0==p_intTotal){
			this.$('#'+this._arrPrivate['arrMultiUpdConfig'].totalprogress_placeholder_id).innerHTML=p_intByteLoaded+'/'+p_intTotal+'&nbsp;'+Math.floor(p_intByteLoaded/1*10000)/100+'%';
		}else{
			this.$('#'+this._arrPrivate['arrMultiUpdConfig'].totalprogress_placeholder_id).innerHTML=p_intByteLoaded+'/'+p_intTotal+'&nbsp;'+Math.floor(p_intByteLoaded/p_intTotal*10000)/100+'%';
		}
	},
	pt.drawSigProcessor=function(p_intByteLoaded,p_intTotal){//可以自定义
		
	},
	/* 绘制展示区 */
	pt.drawPic=function(){//可以自定义
		var a='';
		for( var i in this._arrPrivate['arrList']){
			var str='<table>';
			str+='<tr><td style="border:1px solid #000">status</td><td style="border:1px solid #000">'+this._arrPrivate['arrList'][i].status+'</td></tr>';
			str+='<tr><td style="border:1px solid #000">id</td><td style="border:1px solid #000">'+this._arrPrivate['arrList'][i].id+'</td></tr>';
			str+='<tr><td style="border:1px solid #000">name</td><td style="border:1px solid #000">'+this._arrPrivate['arrList'][i].name+'</td></tr>';
			str+='<tr><td style="border:1px solid #000">size</td><td style="border:1px solid #000">'+this._arrPrivate['arrList'][i].size+'</td></tr>';
			str+='<tr><td style="border:1px solid #000">code</td><td style="border:1px solid #000">'+this._arrPrivate['arrList'][i].code+'</td></tr>';
			str+='<tr><td style="border:1px solid #000">msg</td><td style="border:1px solid #000">'+this._arrPrivate['arrList'][i].msg+'</td></tr>';
			str+='<tr><td style="border:1px solid #000">key</td><td style="border:1px solid #000">'+this._arrPrivate['arrList'][i].key+'</td></tr>';
			str+='<tr><td style="border:1px solid #000">ext</td><td style="border:1px solid #000">'+this._arrPrivate['arrList'][i].ext+'</td></tr>';
			str+='</table>';
			a+=str;
		}	
		this.$('#'+this._arrPrivate['arrMultiUpdConfig'].filelist_placeholder_id).innerHTML=a;
	}
})();